<?php
namespace Controllers;

use Libs\Page;
use Models\PostModel;

class IndexController extends CommonController {
    public function index () {
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
        $pageSize = 5;
        $offset = ($page - 1) * $pageSize;
        $limit = ' limit ' . $offset . ' ,' . $pageSize;
        $where = '';
        $cate_id = isset($_GET['cate_id']) ? intval($_GET['cate_id']) : 0;
        if ($cate_id > 0) $where = ' where cate_id = ' . $cate_id;
        $postModel = new PostModel();
        $postLists = $postModel->getPostList($where, $limit);
        $count = $postModel->getPostCount($where);
        $p = new Page($pageSize, $count);
        return $this->response('index/index', ['postLists' => $postLists, 'pageHtml' => $p->show()]);
    }
}